#!/usr/bin/python
import os, os.path
import re
import glob

oldfiles=glob.glob('*.pyc')
if os.path.exists('rap_core.py'): oldfiles.append('rap_core.py')
for f in oldfiles: os.system('rm '+f)

top=['raplib.py','rap_states.py','rap_trans.py']

allfiles=os.listdir('.')
files=[]
for f in allfiles:
    tmp=re.findall(r'(rap).*(py)',f)
    if len(tmp) > 0 : files.append(f)
for i in range(len(top)):
  files.remove(top[i])
  files.insert(i,top[i])
os.system("cp import.py rap_core.py")
for f in files:
    print f
    os.system("cat rap_core.py "+f+" > temp")
    os.system("mv temp rap_core.py")
